#include "ff.h"
#include "kernel/astralapi.h"

int init_ramfs()
{
    static FATFS fs;
    return f_mount(&fs, "0", 1);
}

int scan_files(char *path)
{
    FRESULT res;
    DIR dir;
    FILINFO fno;

    res = f_opendir(&dir, path);
    if (res != FR_OK)
    {
        return FR_NO_PATH;
    }

    for (;;)
    {
        res = f_readdir(&dir, &fno);
        if (res != FR_OK || fno.fname[0] == 0)
        {
            break;
        }
        if (fno.fattrib & AM_DIR)
        {
            //dir
            kprint("\033[33m%s\033[0m\n", fno.fname);
        }
        else
        {
            //file
            kprint("\033[32m%s\033[0m\n", fno.fname);
        }
    }
    f_closedir(&dir);
    return res;
}